counterfactual1_table <- function(){
  
  # Loading counterfactual results
  indtable <- read.csv("../release/counterfactuals/lowrisk_simplemh_censor0.2/fixedmarkup0/indmarketoutcomes.csv")
  sgtable <- read.csv("../release/counterfactuals/lowrisk_simplemh_censor0.2/fixedmarkup0/sgmarketoutcomes.csv")
  
  # Removing proportion counterfactuals
  indtable <- indtable[, c(1:2, 4, 6)]
  sgtable <- sgtable[, c(1:2, 4, 6)]
  
  # Loading Standard Error Results
  stderrtable <- read.csv("../release/counterfactuals/bootstrap/bootstrap_stderr.csv")
  ## make necesary zeros
  stderrtable[c(1, 13:24), 2] <- 0
  ## remove labels: 
  stderrtable <- stderrtable[, -1]
  ## adding correct names: 
  names(stderrtable) <- names(indtable)
  
  # Loading Small Group Consumer Surplus Estimates
  fee_sg_cs <- read.csv("../release/fee_sg_cs/SG_CS_results.txt")
  
  # Add the preferred CS measure to the sg table
  sgtable[1, 1] <- fee_sg_cs[which(fee_sg_cs$Type == "CS: Full Sample; No Outside Option; Zero Fees"), 2]
  sgtable[2, 1] <- fee_sg_cs[which(fee_sg_cs$Type == "CS: >.05 ; No Outside Option; Zero Fees"), 2]
  sgtable[5, 1] <- fee_sg_cs[which(fee_sg_cs$Type == "CS: Full Sample; No Outside Option; Zero Fees; Low ACG"), 2]
  sgtable[6, 1] <- fee_sg_cs[which(fee_sg_cs$Type == "CS: >.05 ; No Outside Option; Zero Fees; High ACG"), 2]  
    
  # Make consumer surplus change: 
  indtable_cs_change <- (indtable[c(1:2, 5:6), ] - indtable[c(1:2, 5:6), 1])   
  sgtable_cs_change <- (sgtable[c(1:2, 5:6), ] - sgtable[c(1:2, 5:6), 1])
  
  tableinnardslist <- list(
    rbind(
    100 * indtable_cs_change[2, ], 
    100 * stderrtable[1, ],
    100 * indtable[3, ], 
    100 * stderrtable[2, ]), 
    perfectshuffle_df(
      100 * indtable[6:9, ], 
      100 * stderrtable[3:6, ]),
    rbind(
          100 * sgtable_cs_change[2, ],
          100 * stderrtable[13, ],
          100 * sgtable[3, ], 
          100 * stderrtable[14, ]), 
    perfectshuffle_df(
      100 * sgtable[7:10, ], 
      100 * stderrtable[15:18, ]))
  
  rownames <- list(
    c("\\quad Consumer surplus, change from base",
      "",
      "\\quad Government expenditure", 
      ""), 
    c("\\quad Uninsurance",
      "",
      "\\quad Bronze",
      "",
      "\\quad Silver",
      "",
      "\\quad Gold",
      ""), 
    c("\\quad Consumer surplus, change from base",
      "",
      "\\quad Government expenditure",
      ""), 
    c("\\quad Uninsurance",
      "",
      "\\quad Bronze",
      "",
      "\\quad Silver",
      "",
      "\\quad Gold/Platinum",
      "")
  )
  
  MakeLatexTableAdj(
    startcodelist = list(
      "\\begin{table}[H]",
      "\\centering",
      "\\caption{Counterfactual results: outcomes}",
      "\\begin{tabular}{lcccc}",
      "&  &  &  & \\tabularnewline",
      "\\hline", 
      "\\hline",
      "\\multicolumn{5}{c}{Panel A: Individual market}\\\\",
      "\\multicolumn{5}{c}{(N = 178,157)}\\\\",
      "\\midrule",
      " &  & Close & Extended & Mandated \\\\",
      "Counterfactual: & Base & small group & ICHRA & insurance \\\\",
      "\\cmidrule(lr){2-2} \\cmidrule(lr){3-3} \\cmidrule(lr){4-4} \\cmidrule(lr){5-5} ",
      "\\emph{Welfare} & & & & \\\\"),
    tableinnardslist = tableinnardslist,
    tableinnardsroundvec = c(0, 1, 0, 1), 
    stderrlist = list(T, T, T, T),
    inbetweencodelistlist = list(
      list(
        "\\emph{Market shares}& & & & \\\\"
      ), 
      list(
        "\\multicolumn{5}{c}{ } \\\\",
        "\\multicolumn{5}{c}{Panel B: Small group market} \\\\",
        "\\multicolumn{5}{c}{(Base: N = 55,374; Merged: N =  125,527)} \\\\",
        "\\midrule",
        "\\emph{Welfare} & & & & \\\\"),
      list(
        "\\emph{Market shares} & & & & \\\\"
      )),
    endcodelist = list(
      "\\hline", 
      "\\hline",
      "\\end{tabular}",
      "\\label{tab:main_t_ctfls1}",
      "\\end{table}"), 
    rownames = rownames
  )
}
